# -*- coding: utf-8 -*-


class transCookie:
    def __init__(self, cookie):
        self.cookie = cookie

    def stringToDict(self):
        '''
        将从浏览器上Copy来的cookie字符串转化为Scrapy能使用的Dict
        :return:
        '''
        itemDict = {}
        items = self.cookie.split(';')
        for item in items:
            key = item.split('=')[0].replace(' ', '')
            value = item.split('=')[1]
            itemDict[key] = value
        return itemDict


if __name__ == "__main__":
    # cookie = input('请输入cookie:')
    # cookie = "hng=CN%7Czh-CN%7CCNY%7C156; lid=%E6%89%93%E4%B8%8D%E5%80%92%E7%9A%84%E5%BC%A0%E4%BA%9A%E9%A3%9E; cna=xRiAE3nzSnkCAXZKPc0ZvN5P; otherx=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0; _med=dw:1366&dh:768&pw:1366&ph:768&ist:0; x=__ll%3D-1%26_ato%3D0; tk_trace=1; t=5db3de9d135063fd9f8b78cf4b629c77; _tb_token_=ee13e4d37fe7a; cookie2=36d65d2b8320c33ca8ef4a3efb6c32b4; swfstore=62136; uc1=cookie16=UIHiLt3xCS3yM2h4eKHS9lpEOw%3D%3D&cookie21=UtASsssmeW6lpyd%2BB%2B3t&cookie15=UtASsssmOIJ0bQ%3D%3D&existShop=false&pas=0&cookie14=UoTfKj3YJ%2Bam7w%3D%3D&tag=8&lng=zh_CN; uc3=vt3=F8dBzrhDnCXqrzWJmWs%3D&id2=UUtKeMoPwNRIgA%3D%3D&nk2=1z72ONRyHbQlONnv9dw%3D&lg2=Vq8l%2BKCLz3%2F65A%3D%3D; tracknick=%5Cu6253%5Cu4E0D%5Cu5012%5Cu7684%5Cu5F20%5Cu4E9A%5Cu98DE; _l_g_=Ug%3D%3D; ck1=""; unb=2317848838; lgc=%5Cu6253%5Cu4E0D%5Cu5012%5Cu7684%5Cu5F20%5Cu4E9A%5Cu98DE; cookie1=VvaPXU7dNVLAY7S2mpSRALhhCCe9wnnausy5crbSjoE%3D; login=true; cookie17=UUtKeMoPwNRIgA%3D%3D; _nk_=%5Cu6253%5Cu4E0D%5Cu5012%5Cu7684%5Cu5F20%5Cu4E9A%5Cu98DE; uss=""; csg=365478f6; skt=b93c7b91a77f6456; enc=8F1r8fXLGlGrkBsOAfGFZ89%2Bgbta3GbZbIFKplh3%2FL5Msw6OwmRtD91wr9RIzn55%2BOn%2BQP8e8fxDdxbq%2FnNsIg%3D%3D; tt=tmall-main; pnm_cku822=098%23E1hvovvUvbpvUvCkvvvvvjiPPszy0jtRPsMhgjnEPmPUtjE2RsdUgjlnP2SvQjYbiQhvCvvv9UUCvpvVvvpvvhCvKphv8vvvvvCvpvvvvvmm86CvmEZvvUUdphvWvvvv9krvpv3Fvvmm86CvmVREvpvVmvvC9jXvuphvmvvv92bQAAefmphvLvpuWpvjOezh6j7J%2B3%2Biaf2EIEkffvDr1nClDCODN%2BLUaNoAdc9D%2BExr1CeKNpKYiXVvVCODN%2BLUaNpqrADn9WmQD40Oam56AnFhHdUPvpvhvv2MMsyCvvpvvvvv; res=scroll%3A1349*6610-client%3A1349*613-offset%3A1349*6610-screen%3A1366*768; whl=-1%260%260%260; isg=BDAwZlS6H3wIIsMtssyKmvJYAf5C0Ra5Y1KcLyqBggte5dCP0onkU4bfOa0g9cyb"
    cookie ='_ga=GA1.2.750199924.1533563172; _gid=GA1.2.876361711.1533563172; user_trace_token=20180806214624-1bdbc0d0-997f-11e8-b72d-525400f775ce; LGUID=20180806214624-1bdbc564-997f-11e8-b72d-525400f775ce; index_location_city=%E5%85%A8%E5%9B%BD; WEBTJ-ID=20180807172252-16513b23ca85-001a28ca5ba692-444a002e-1049088-16513b23ca976; JSESSIONID=ABAAABAAAFCAAEG9C1883AF097DA6EE23D3E4F9AD22793D; Hm_lvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1533563171,1533633773,1533636706; X_HTTP_TOKEN=4235765fc7540813f96fb983e97ae2fa; ab_test_random_num=0; _putrc=169F433E50531B20123F89F2B170EADC; login=true; hasDeliver=0; gate_login_token=b434e7537e5b7f3010b67dc54bbe85134d93f0339417dd0ce9021ebe02eb0833; unick=%E6%8B%89%E5%8B%BE%E7%94%A8%E6%88%B77116; mds_login_authToken="K4i20OPux7Kiv3leAko5/GHZ6P0/xIoVHnyLnfhjaGibI+jr1W5wJfkbzhI1DUcjrrNOZVF3uarSuprrNpLVFSBFBiF0JkHWLtGJvyP0ZYIQaDwLmqBlE8f2Z9OuxYmL3Ov4mINttxjoHeWc115OjR+A299vKg5KYI2KwVp3zTB4rucJXOpldXhUiavxhcCELWDotJ+bmNVwmAvQCptcy5e7czUcjiQC32Lco44BMYXrQ+AIOfEccJKHpj0vJ+ngq/27aqj1hWq8tEPFFjdnxMSfKgAnjbIEAX3F9CIW8BSiMHYmPBt7FDDY0CCVFICHr2dp5gQVGvhfbqg7VzvNsw=="; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2216513fc258d2d-07eeecd0ac36c9-444a002e-1049088-16513fc258e27f%22%2C%22%24device_id%22%3A%2216513fc258d2d-07eeecd0ac36c9-444a002e-1049088-16513fc258e27f%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%7D; TG-TRACK-CODE=index_navigation; LGSID=20180807191701-683e1516-9a33-11e8-b78e-525400f775ce; PRE_UTM=; PRE_HOST=; PRE_SITE=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist_python%2520%3FlabelWords%3D%26fromSearch%3Dtrue%26suginput%3D; PRE_LAND=https%3A%2F%2Fwww.lagou.com%2Fjobs%2Flist_python%25E6%2595%25B0%25E6%258D%25AE%25E5%2588%2586%25E6%259E%2590%3Foquery%3Dpython%26fromSearch%3Dtrue%26labelWords%3Drelative; _gat=1; SEARCH_ID=74bc268ea1054d3b86525570de2cc482; LGRID=20180807192813-f8569b0b-9a34-11e8-b78e-525400f775ce; Hm_lpvt_4233e74dff0ae5bd0a3d81c6ccf756e6=1533641280'
    trans = transCookie(cookie)
    print(trans.stringToDict())